package com.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;


public class Character2Filter implements Filter
{
	protected FilterConfig filterConfig = null;


	public void init(FilterConfig filterConfig) throws ServletException
	{
		
	}
	
	public void destroy()
	{
		this.filterConfig = null;
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException
	{
		System.out.println("Character2Filter");
		request.setCharacterEncoding("GBK");
		String flag  =  request.getParameter("flag");
		System.out.println(flag);
		String flagEnc = URLEncoder.encode(flag, "UTF-8");
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		//httpResponse.setCharacterEncoding("UTF-8");
		httpResponse.sendRedirect("/gapp/myTest/testCharset2?flag="+flagEnc);
		return;				
	}
}
